home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / Find duplicates.ifs < prev    next >
Encoding:
Text File  |  2004-03-20  |  2.9 KB  |  108 lines

  1. // SCRIPTING
  2. // Find duplicates in a list
  3.  
  4. (***************************************************
  5.  *  Script to find duplicates in the list of       *
  6.  *  selected movies.                               *
  7.  *  It doesn't see empty fields.                   *
  8.  *                                                 *
  9.  * (c) 2003 Louis Francisco ork@everydayangels.net *
  10.  *                                                 *
  11.  *  For use with Ant Movie Catalog 3.4.1           *
  12.  *  www.antp.be/software/moviecatalog              *
  13.  *                                                 *
  14.  *  This program is free software; you can         *
  15.  *  redistribute it and/or modify it under the     *
  16.  *  terms of the GNU General Public License as     *
  17.  *  published by the Free Software Foundation;     *
  18.  *  either version 2 of the License, or (at your   *
  19.  *  option) any later version.                     *
  20.  ***************************************************)
  21. program FindDuplicates;
  22. const
  23.   NMAX=260; //Set to the last number in the list
  24. var
  25.   Titles:TStringList;
  26.   Numbers:TStringList;
  27.   Duplicates:TStringList;
  28.   CurrentTitle:string;
  29.   CurrentNumber:string;
  30.  
  31. function FindTitle(title:string;list:TStringList):integer;
  32. var
  33.   i:integer;
  34. begin
  35.   result:=-1;
  36.   for i:=0 to list.Count-1 do
  37.   begin
  38.     if list.GetString(i)=title then
  39.     begin
  40.       result:=i;
  41.       break;
  42.     end;
  43.   end;
  44. end;
  45.  
  46. procedure FindDuplicates();
  47. var
  48.   numTitle,numDup:integer;
  49. begin
  50.   numTitle:=FindTitle(CurrentTitle,Titles);
  51.   if numTitle<>-1 then
  52.   begin
  53.     numDup:=FindTitle(CurrentTitle,Duplicates);
  54.     if numDup=-1 then
  55.     begin
  56.       Duplicates.Text:=Duplicates.Text+
  57.         CurrentTitle+' ('+Numbers.GetString(numTitle)
  58.         +', '+CurrentNumber;
  59.     end
  60.     else
  61.     begin
  62.       Duplicates.SetString(numDup,
  63.         Duplicates.GetString(numDup)+', '+CurrentNumber);
  64.     end;
  65.   end;
  66.   Titles.Text:=Titles.Text+CurrentTitle;
  67.   Numbers.Text:=Numbers.Text+CurrentNumber;
  68. end;
  69.  
  70. procedure SaveToFile(fileName:string);
  71. var
  72.   i:integer;
  73. begin
  74.   for i:=0 to Duplicates.Count-1 do
  75.   begin
  76.     Duplicates.SetString(i,Duplicates.GetString(i)+')');
  77.   end;
  78.   Duplicates.SaveToFile(fileName);
  79. end;
  80.  
  81. begin
  82.   if CheckVersion(3,4,1) then
  83.   begin
  84.     if Titles=nil then
  85.     begin
  86.       Titles:=TStringList.Create;
  87.       Numbers:=TStringList.Create;
  88.       Duplicates:=TStringList.Create;
  89.     end;
  90.  
  91.     CurrentTitle:=GetField(fieldOriginalTitle);
  92.     CurrentNumber:=GetField(fieldNumber);
  93.     // If title is empty, it generates bugs while looking to the
  94.     // number of a duplicate movie.
  95.     if CurrentTitle<>'' then FindDuplicates;
  96.  
  97.     if StrToInt(CurrentNumber,0)=NMAX then
  98.     begin
  99.       SaveToFile('c:\duplicates.txt');
  100.       Titles.Free;
  101.       Numbers.Free;
  102.       Duplicates.Free;
  103.     end;
  104.   end
  105.   else
  106.     ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.1)');
  107. end.
  108.